package com.jinji.customer.service.impl;

import cn.hutool.core.map.MapUtil;
import com.jinji.common.exception.JinJiException;
import com.jinji.common.util.MicroAppUtil;
import com.jinji.customer.dao.CustomerDao;
import com.jinji.customer.service.CustomerService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class CustomerServiceImpl implements CustomerService {

    @Value("${tencent.cloud.secretId}")
    private String secretId;

    @Value("${tencent.cloud.secretKey}")
    private String secretKey;

    @Value("${tencent.cloud.face.region}")
    private String region;

    @Value("${tencent.cloud.face.groupName}")
    private String groupName;

    @Resource
    private MicroAppUtil microAppUtil;
    @Resource
    private CustomerDao customerDao;


    @Override
    @Transactional
    public String registerNewDriver(Map param) {
        String code = MapUtil.getStr(param, "code");
        String openId = microAppUtil.getOpenId(code);
        //判判用户是否存在
        HashMap tempParam = new HashMap() {{
            put("openId", openId);
        }};
        if (customerDao.hasDriver(tempParam) != 0) {
            throw new JinJiException("该微信无法注册, 已经注册过了");
        }
        //插入到司机表
        param.put("openId", openId);
//        customerDao.registerNewDriver(param);
//        String customerId = customerDao.searchDriverId(openId);

        return "customerId";
    }


//    @Override
//    public HashMap login(String code) {
//        String openId = microAppUtil.getOpenId(code);
//        HashMap result = customerDao.login(openId);
//        if (result != null && result.containsKey("archive")) {
//            int temp = MapUtil.getInt(result, "archive");
//            boolean archive = temp == 1 ? true : false;
//            result.replace("archive", archive);
//        }
//        return result;
//    }


}
